﻿using OD.ToolBox.IO;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace OD.ProjectCustomizationTool.Helpers
{
    internal static class SourceControlHelper
    {
        private static String PathToTfExe { get { return PathHelper.BuildFullPathToResource("TF.exe"); } }

        /// <summary>
        /// Add a file or a folder to the source control. The user will be able to commit it.
        /// </summary>
        /// <param name="path">The full local path to the file or the folder.</param>
        /// <param name="logger">The object that logs what happens.</param>
        public static void Add(String path, ILogger logger)
        {
            if (String.IsNullOrEmpty(path))
            {   // This code has been generated from the 'argnullString' custom snippet.
                throw new ArgumentNullException("path");
            }
            if (String.IsNullOrEmpty(path.Trim()))
            {   // This code has been generated from the 'argnullString' custom snippet.
                throw new ArgumentException("The argument 'path' contains only white spaces.", "path");
            }
            if (logger == null)
            {   // This code has been generated from the 'argnull' custom snippet.
                throw new ArgumentNullException("logger");
            }

            logger.WriteLine("Adding to source control '" + path + "'");
            Process.Start(SourceControlHelper.PathToTfExe, "add \"" + path + "\" /recursive /noignore");
        }

        /// <summary>
        /// Check out a file or a folder from the source control. The user will be able to commit it.
        /// </summary>
        /// <param name="path">The full local path to the file or the folder.</param>
        /// <param name="logger">The object that logs what happens.</param>
        public static void CheckOut(String path, ILogger logger)
        {
            if (String.IsNullOrEmpty(path))
            {   // This code has been generated from the 'argnullString' custom snippet.
                throw new ArgumentNullException("path");
            }
            if (logger == null)
            {   // This code has been generated from the 'argnull' custom snippet.
                throw new ArgumentNullException("logger");
            }

            logger.WriteLine("Checking out '" + path + "'");
            Process.Start(SourceControlHelper.PathToTfExe, "checkout \"" + path + "\"");
        }
    }
}
